#!/usr/bin/perl


# perl -e 'print "hello world\n"' 
print "hello world\n";


$num=123;
$float=123.11;
$hex_num=0x01;

$str="123";

@arr=(1,2,3);

# hash

print("== hash ==\n");
%hash=('a'=>1,'b'=>2); 
%data = ('google', 45, 'runoob', 30, 'taobao', 40);
print "\$data{'google'} = $data{'google'}\n";
print "\$data{'runoob'} = $data{'runoob'}\n";
print "\$data{'taobao'} = $data{'taobao'}\n";


# array
print("== array ==\n");
@hits = (25, 30, 40);             
@names = ("google", "runoob", "taobao");
 
print "\$hits[0] = $hits[0]\n";
print "\$hits[1] = $hits[1]\n";
print "\$hits[2] = $hits[2]\n";

print "\$names[0] = $names[0]\n";
print "\$names[1] = $names[1]\n";
print "\$names[2] = $names[2]\n";

# perl condition 
print("== condition ==\n");
$favorite = 10;     # 喜欢数
$status = ($favorite > 60 )? "热门网站" : "不是热门网站";
print("$status \n");

print("==> if else\n");
$a = 100;
# 使用 == 判断两个数是否相等
if( $a  ==  20 ){
    # 条件为 true 时执行
    printf "a 的值为 20\n";
}elsif( $a ==  30 ){
    # 条件为 true 时执行
    printf "a 的值为 30\n";
}else{
    # 以上所有的条件为 false 时执行
    printf "a 的值为 $a\n";
}

print("==> unless\n");
$a = 20;
# 使用 unless 语句检测布尔表达式
unless( $a < 20 ){
    # 布尔表达式为 false 时执行
    printf "a 大于等于 20\n";
}
print "a 的值为 : $a\n";

$a = "";
# 使用 unless 语句检测布尔表达式
unless ( $a ){
    # 布尔表达式为 false 时执行
    printf "条件 a 为 false\n";
}
print "a 的值为 : $a\n";


print("\n== loop ==\n");
print("==> while\n");
print("==> until\n");
print("==> for\n");
print("==> foreach\n");
print("==> do while\n");
print("==> while\n");
print("==> while\n");
print("==> dead loop\n");
#for( ; ; )
#{
#   printf "循环会无限执行。\n";
#}


print("\n== RegExp ==\n");
# https://www.runoob.com/perl/perl-regular-expressions.html





